<?php

namespace App\Edu\Controllers;

use App\Edu\Facades\EduCourseFacade;
use App\Edu\Facades\EduPaperFacade;
use App\Edu\Facades\EduQuestionFacade;
use App\Http\Controllers\BaseController;
use App\Services\AuthUser;
use Illuminate\Http\Request;

class EduController extends BaseController
{
    use AuthUser;

    /** 
     * 试卷保存
     */
    public function savePaper(Request $request)
    {
        $this->validate($request, [
            'cate_id' => 'required',
            'paper_type' => 'required|integer',
            'question' => 'required',
        ]);
        $params = $request->only(['paper_id', 'cate_id', 'paper_type', 'question']);
        return EduPaperFacade::saveInfo($params);
    }

    /** 
     * 试卷删除
     */
    public function deletePaper(Request $request)
    {
        $this->validate($request, [
            'paper_id' => 'required|integer',
        ]);
        return EduPaperFacade::deletePaper($request->input('paper_id'));
    }

    /** 
     * 试卷启用，禁用
     */
    public function changePaperStatus(Request $request)
    {
        $this->validate($request, [
            'paper_id' => 'required|integer',
        ]);
        return EduPaperFacade::changePaperStatus($request->input('paper_id'));
    }

    /** 
     * 获取试卷列表
     */
    public function getPaperList(Request $request)
    {
        $this->validate($request, [
            'page' => 'integer',
            'page_size' => 'integer',
        ]);
        return EduPaperFacade::paperList($request->all());
    }

    /** 
     * 课程列表
     */
    public function getCourseList(Request $request)
    {
        $this->validate($request, [
            'page' => 'integer',
            'page_size' => 'integer',
        ]);
        return EduCourseFacade::courseList($request->all());
    }

    /** 
     * 课程保存
     */
    public function saveCourse(Request $request)
    {
        $this->validate($request, [
            'course_id' => 'integer',
            'course_title' => 'required|integer',
            'course_image' => 'required',
            'course_desc' => 'required',
        ]);
        $params = $request->all();
        $params['user_id'] = $this->getAuthUserId();
        return EduCourseFacade::saveInfo($params);
    }

    /** 
     * 删除课程
     */
    public function deleteCourse(Request $request)
    {
        $this->validate($request, [
            'course_id' => 'required|integer',
        ]);
        return EduCourseFacade::deleteInfo($request->input('course_id'));
    }

    /** 
     * 课程启用，禁用
     */
    public function changeCourseStatus(Request $request)
    {
        $this->validate($request, [
            'course_id' => 'required|integer',
        ]);
        return EduCourseFacade::changeCourseStatus($request->input('course_id'));
    }

    /** 
     * 课时保存
     */
    public function saveCourseLesson(Request $request)
    {
        $this->validate($request, [
            'course_id' => 'required|integer',
            'lesson_id' => 'integer',
            'parent_id' => 'integer',
            'lesson_name' => 'required',
        ]);
        $params = $request->all();
        return EduCourseFacade::saveLessonInfo($params);
    }

    /** 
     * 删除课时
     */
    public function deleteCourseLesson(Request $request)
    {
        $this->validate($request, [
            'lesson_id' => 'required|integer',
        ]);
        return EduCourseFacade::deleteLessonInfo($request->input('lesson_id'));
    }

    /** 
     * 获取试题分类
     */
    public function getQuestionType()
    {
        return EduPaperFacade::getQuestionType();
    }

    /** 
     * 试题保存
     */
    public function saveQuestion(Request $request)
    {
        $this->validate($request, [
            'question_id' => 'integer',
            'question_title' => 'required|integer',
            'cateid' => 'integer',
            'province_id' => 'integer',
            'question_type' => 'required',
            'question_option' => 'required',
            'question_answer' => 'required'
        ]);
        $params = $request->all();
        return EduQuestionFacade::saveInfo($params);
    }

    /** 
     * 导入word试卷
     */
    public function importPaper(Request $request)
    {
        $this->validate($request, [
            // 'file' => 'required',
            // 'json_data' => 'required'
        ]);
        return EduPaperFacade::importPaper($request->input('file', ''), $request->input('json_data', ''));
    }
}
